package StudyCode.summary.mycollection;

import java.util.function.Predicate;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class FindTheFirstElementInTheArrayThatMatchesThePredicate {
	public static <T> T findFirstMatch(T[] input, Predicate<T> predicate) {

		for (T element : input) {
			if (predicate.test(element)) {
				return element;
			}
		}
		return null;
	}

	public static <T> T findFirstMatch(T[][] input, Predicate<T> predicate) {

		for (T[] row : input) {
			for (T element : row) {
				if (predicate.test(element)) {
					return element;
				}
			}
		}
		return null;
	}
}
